package com.homework.Tools;

import java.util.Arrays;

public class Arr_cau_sort {

  public static int[] arr_arrangement(double[] arr) {
    int[] new_arr = new int[arr.length];
    int i = 0;
    for (double x : arr) {
      new_arr[i] = (int)Math.round(x);
      i += 1;
    }
    return new_arr;
  }

  public static int[] Math_sort(int[] arr){
    for (int i = 0; i <arr.length-1; i++) {
      for (int j = 0; j < arr.length-1-i; j++) {
        int temp = Math.max(arr[j],arr[j+1]);
        arr[j] = Math.min(arr[j],arr[j+1]);
        arr[j+1] = temp;
      }
    }
    return arr;
  }

  public static void main(String[] args) {
    // 有一个double型的数组{12.23,22.1.jpg,8.88,55.5,33.78},
    // 要求对该数组里的每个数进行四舍五入，然后存入int型的数组中，最后对该数组进行升序排序（使用java.lang.Math类中的方法）。
    double[] darr = {12.23, 22.1, 8.88, 55.5, 33.78,44.45,76.32,0.0};
    int[] iarr = Arr_cau_sort.arr_arrangement(darr);
    System.out.println(Arrays.toString(Arr_cau_sort.Math_sort(iarr)));
  }
}
